package cn.highedu.restclient.demos;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class RestClientController {

    Logger logger = org.slf4j.LoggerFactory.getLogger(RestClientController.class);

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/rest/hello/{name}")
    public String restHello(@PathVariable String name) {
        String url = "http://localhost:8080/hello/{0}";
        logger.info("restTemplate url: {}", url);
        String result = restTemplate.getForObject(url, String.class, name);
        logger.info("restTemplate result: {}", result);
        return result;
    }
}
